//
//  YQWalletDetailHeadView.m
//  NewRetail
//
//  Created by yuqin on 2019/6/25.
//  Copyright © 2019 yuqin. All rights reserved.
//

#import "YQWalletDetailHeadView.h"

@implementation YQWalletDetailHeadView

- (void)setupContentView {
    self.backgroundColor = WhiteColor;
    [self addSubview:self.icon];
    [self addSubview:self.coinTF];
    [self addSubview:self.changedBtn];
    [self addSubview:self.addresslLab];
    [self addSubview:self.rightBtn];
    
    CGFloat textField_W = ScreenWidth/2.0-kMargin_left+FIT(27);
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(FIT(24));
        make.centerX.mas_equalTo(self.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(FIT(54), FIT(54)));
    }];
    
    [self.coinTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kMargin_left);
        make.top.equalTo(self.icon.mas_bottom).mas_equalTo(FIT(25));
        make.size.mas_equalTo(CGSizeMake(textField_W, FIT(20)));
    }];
    
    [self.changedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon.mas_bottom).mas_equalTo(FIT(25));
        make.left.equalTo(self.coinTF.mas_right).mas_equalTo(FIT(12));
        make.size.mas_equalTo(CGSizeMake(FIT(15), FIT(15)));
    }];
    
    [self.addresslLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.coinTF.mas_bottom).mas_equalTo(FIT(24));
        make.centerX.mas_equalTo(self.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(FIT(120), FIT(12)));
    }];
    
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.addresslLab.mas_right).mas_equalTo(FIT(10));
        make.centerY.mas_equalTo(self.addresslLab.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(FIT(20), FIT(20)));
    }];
    
}

- (UIImageView *)icon {
    if (!_icon) {
        _icon = [YQViewFactory imageViewWithImage:YQ_IMAGE(@"")];
        _icon.layer.cornerRadius = FIT(54)/2.0;
        _icon.layer.masksToBounds = YES;
        _icon.backgroundColor = MainRedTextColor;
    }
    return _icon;
}

- (UITextField *)coinTF {
    //钱包的名称 默认不可点击  点击修改打开交换
    if (!_coinTF) {
        _coinTF = [YQViewFactory textFieldWithPlaceholderText:@"钱包名称" textColor:UIColorFromRGB(0x5682E4) fontSize:FIT(19) userBold:YES];
        _coinTF.text = @"WDC";
        _coinTF.enabled = NO;
        _coinTF.textAlignment = NSTextAlignmentRight;
    }
    return _coinTF;
}

- (UIButton *)changedBtn {
    if (!_changedBtn) {
        _changedBtn = [YQViewFactory buttonWithImage:YQ_IMAGE(@"changed") target:self sel:@selector(changedWalletName)];
    }
    return _changedBtn;
}

- (UILabel *)addresslLab {
    if (!_addresslLab) {
        _addresslLab = [YQViewFactory labelWithTextColor:UIColorFromRGB(0xcccccc) textAlignment:NSTextAlignmentCenter fontSize:FIT(15) userBold:NO];
        _addresslLab.text = @"0073bddke325wefjlwefslfk4515cc65";
        _addresslLab.lineBreakMode = NSLineBreakByTruncatingMiddle;
    }
    return _addresslLab;
}

- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [YQViewFactory buttonWithImage:YQ_IMAGE(@"copy") target:self sel:@selector(copyAction)];
        
    }
    return _rightBtn;
}

- (void)changedWalletName {
    self.coinTF.enabled = YES;
    [self.coinTF becomeFirstResponder];
}

- (void)copyAction {
    UIPasteboard *paste = [UIPasteboard generalPasteboard];
    [paste setString:self.addresslLab.text];
    if (paste == nil) {
        [LCProgressHUD showFailure:@"复制失败"];
    }else {
        [LCProgressHUD showSuccess:@"已复制到粘贴板"];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.coinTF resignFirstResponder];
}

@end
